package com.gjy.util.concurrent;

import java.util.concurrent.RecursiveTask;

/**
 * @author 宫静雨
 * @version 1.0
 * @since 2023-10-25 09:25:24
 */
public class Fibonacci extends RecursiveTask<Integer> {

    private final Integer n;

    public Fibonacci(Integer n) {
        this.n = n;
    }

    @Override
    protected Integer compute() {
        if (n <= 1)
            return n;
        Fibonacci f1 = new Fibonacci(n - 1);
        f1.fork();
        Fibonacci f2 = new Fibonacci(n - 2);
        return f2.compute() + f1.join();
    }
}
